package com.mall.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageInfo;
import com.mall.db.domain.Region;
import com.mall.db.service.RegionService;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("system/rc")
public class RegionController extends BaseController<Region> {

    @Resource(name = "regionService")
    private RegionService rs;

    @Override
    public Map<String, Object> find(Region region) {
        //PageHelper.startPage(region.getPage(), region.getLimit());
        QueryWrapper<Region>qw=new QueryWrapper<>();
       if(!StringUtils.isEmpty(region.getType())){
           qw.eq("type", region.getType());
       }
       if(!StringUtils.isEmpty(region.getName())){
           qw.eq("name", region.getName());
       }
       if(!StringUtils.isEmpty(region.getPid())){
           qw.eq("pid",region.getPid());
       }
        if(!StringUtils.isEmpty(region.getCode())){
            qw.eq("code",region.getCode());
        }
        List<Region>list= rs.list(qw);
        PageInfo<Region> page=new PageInfo<>(list, region.getLimit());

        return this.findMap(page.getList(), page.getTotal());
    }
}
